package 砖墙554;

import java.util.*;

/**
 * @author 谢阳
 * @version 1.8.0_131
 */
class Solution {
    public static void main(String[] args) {
        ArrayList<List<Integer>> lists = new ArrayList<>();
        ArrayList<Integer> list = new ArrayList<>();
        list.add(1);
        lists.add(list);
        lists.add(list);
        lists.add(list);
        int i = leastBricks(lists);
        System.out.println(i);
    }

    public static int leastBricks(List<List<Integer>> wall) {
        HashMap<Integer, Integer> hashMap = new HashMap<>();

        for (List<Integer> integers : wall) {
            int sum = 0;
            for (int i = 0; i < integers.size() - 1; i++) {
                sum += integers.get(i);
                hashMap.put(sum, hashMap.getOrDefault(sum, 0) + 1);
            }
        }

        int max = 0;
        for (Integer value : hashMap.values()) {
            if (max < value) {
                max = value;
            }
        }
        return wall.size() - max;
    }
}
